package com.phpxiu.app.emotion;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @file
 * @brief 表情数据对象封装
 * @author 吴金洲
 * @note 表情数据对象封装
 *
 */
public class EmotionIcon implements Parcelable {

    public static final Creator<EmotionIcon> CREATOR = new Creator<EmotionIcon>() {
        @Override
        public EmotionIcon createFromParcel(Parcel in) {
            return new EmotionIcon(in);
        }

        @Override
        public EmotionIcon[] newArray(int size) {
            return new EmotionIcon[size];
        }
    };

    private int icon;

    private char value;

    private String emotion;

    private boolean isEmpty=false;
    private boolean isDEl=false;//删除按钮

    public EmotionIcon(int icon, char value, String emotion) {
        this.icon = icon;
        this.value = value;
        this.emotion = emotion;
    }

    public EmotionIcon(Parcel in) {
        this.icon = in.readInt();
        this.value = (char) in.readInt();
        this.emotion = in.readString();
    }

    public EmotionIcon() {

    }

    public EmotionIcon(String emotion) {
        this.emotion = emotion;
    }

    public static EmotionIcon fromResource(int icon, int value) {
        EmotionIcon emotion = new EmotionIcon();
        emotion.icon = icon;
        emotion.value = (char) value;
        return emotion;
    }

    public static EmotionIcon fromCodePoint(int codePoint) {
        EmotionIcon emotion = new EmotionIcon();
        emotion.emotion = newString(codePoint);
        return emotion;
    }

    public static EmotionIcon fromChar(char ch) {
        EmotionIcon emotion = new EmotionIcon();
        emotion.emotion = Character.toString(ch);
        return emotion;
    }

    public static EmotionIcon fromChars(String chars) {
        EmotionIcon emotion = new EmotionIcon();
        emotion.emotion = chars;
        return emotion;
    }

    public static final String newString(int codePoint) {
        if (Character.charCount(codePoint) == 1) {
            return String.valueOf(codePoint);
        } else {
            return new String(Character.toChars(codePoint));
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(icon);
        dest.writeInt(value);
        dest.writeString(emotion);
    }

    public char getValue() {
        return value;
    }

    public int getIcon() {
        return icon;
    }

    public String getEmotion() {
        return emotion;
    }

    @Override
    public boolean equals(Object o) {
        return o instanceof EmotionIcon && emotion.equals(((EmotionIcon) o).emotion);
    }

    @Override
    public int hashCode() {
        return emotion.hashCode();
    }

    public boolean isEmpty() {
        return isEmpty;
    }

    public void setEmpty(boolean isEmpty) {
        this.isEmpty = isEmpty;
    }

    public boolean isDEl() {
        return isDEl;
    }

    public void setDEl(boolean isDEl) {
        this.isDEl = isDEl;
    }
}
